package com.fac.controller.admin;

import com.fac.dto.CategoryCreateDTO;
import com.fac.dto.CategoryPageQueryDTO;
import com.fac.entity.EquipmentCategory;
import com.fac.result.PageResult;
import com.fac.result.Result;
import com.fac.service.EquipmentCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

/**
 * 设备分类管理控制器
 */
@RestController
@RequestMapping("/admin/categories")
@Api(tags = "管理端-设备分类管理相关接口")
@Slf4j
public class EquipmentCategoryController {

    @Autowired
    private EquipmentCategoryService equipmentCategoryService;

    /**
     * 创建设备分类
     *
     * @param categoryCreateDTO 设备分类创建DTO
     * @return 创建结果
     */
    @PostMapping
    @ApiOperation("创建设备分类")
    @ResponseStatus(HttpStatus.CREATED)
    public Result<EquipmentCategory> create(@RequestBody CategoryCreateDTO categoryCreateDTO) {
        log.info("创建设备分类：{}", categoryCreateDTO);
        EquipmentCategory category = equipmentCategoryService.create(categoryCreateDTO);
        return Result.success(category);
    }

    /**
     * 分页查询设备分类
     *
     * @param categoryPageQueryDTO 分页查询条件
     * @return 分页结果
     */
    @GetMapping
    @ApiOperation("分页查询设备分类")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO) {
        log.info("分页查询设备分类：{}", categoryPageQueryDTO);
        PageResult pageResult = equipmentCategoryService.pageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据ID查询设备分类
     *
     * @param categoryId 分类ID
     * @return 设备分类
     */
    @GetMapping("/{categoryId}")
    @ApiOperation("根据ID查询设备分类")
    public Result<EquipmentCategory> getById(@PathVariable Long categoryId) {
        log.info("根据ID查询设备分类：{}", categoryId);
        EquipmentCategory category = equipmentCategoryService.getById(categoryId);
        return Result.success(category);
    }

    /**
     * 删除设备分类
     *
     * @param categoryId 分类ID
     * @return 删除结果
     */
    @DeleteMapping("/{categoryId}")
    @ApiOperation("删除设备分类")
    public Result<String> delete(@PathVariable Long categoryId) {
        log.info("删除设备分类：{}", categoryId);
        equipmentCategoryService.deleteById(categoryId);
        return Result.success();
    }
} 